﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;

public partial class PersonalManager_Staff : System.Web.UI.Page
{
    List<Staff> list = new StaffManager().GetAllStaff("", "", "");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.gvStaff.DataSource = list;
            this.gvStaff.DataBind();

        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddStaff.aspx");
    }

    public bool GetBool(object status)
    {
        if (Convert.ToInt32(status) == 1)
        {
            return true;
        }
        if (Convert.ToInt32(status) == 0)
        {
            return false;
        }
        return false;
    }
    protected void gvStaff_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView theGrid = sender as GridView;   // refer to the GridView
        int newPageIndex = 0;
        newPageIndex = e.NewPageIndex;
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        theGrid.PageIndex = newPageIndex;
        this.gvStaff.DataSource = list;
        this.gvStaff.DataBind();
    }
    protected void gvStaff_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int stfId = (int)gvStaff.DataKeys[e.RowIndex].Value;
        Response.Redirect(string.Format("AddStaff.aspx?id={0}", stfId));
    }
    protected void gvStaff_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string status = ((Label)(e.Row.Cells[5].FindControl("lbStatus"))).Text;
            if (status == "1")
            {
                ((RadioButton)(e.Row.Cells[5].FindControl("rbOk"))).Checked = true;
            }
            if (status == "0")
            {
                ((RadioButton)(e.Row.Cells[5].FindControl("rbNo"))).Checked = true;
            }

        }

    }
}